package com.ruoyi.project.channel.salesmanScore.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.salesmanScore.domain.SalesmanScore;
import com.ruoyi.project.channel.salesmanScore.service.ISalesmanScoreService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 业务员加减分信息操作处理
 * 
 * @author CAIN
 * @date 2025-01-01
 */
@Controller
@RequestMapping("/channel/salesmanScore")
public class SalesmanScoreController extends BaseController
{
    private String prefix = "channel/salesmanScore";
	
	@Autowired
	private ISalesmanScoreService salesmanScoreService;
	
	@RequiresPermissions("channel:salesmanScore:view")
	@GetMapping()
	public String salesmanScore()
	{
	    return prefix + "/salesmanScore";
	}
	
	/**
	 * 查询业务员加减分列表
	 */
	@RequiresPermissions("channel:businessInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SalesmanScore salesmanScore)
	{
		startPage();
        List<SalesmanScore> list = salesmanScoreService.selectSalesmanScoreList(salesmanScore);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出业务员加减分列表
	 */
	@RequiresPermissions("channel:businessInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SalesmanScore salesmanScore)
    {
    	List<SalesmanScore> list = salesmanScoreService.selectSalesmanScoreList(salesmanScore);
        ExcelUtil<SalesmanScore> util = new ExcelUtil<SalesmanScore>(SalesmanScore.class);
        return util.exportExcel(list, "salesmanScore");
    }
	
	/**
	 * 新增业务员加减分
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存业务员加减分
	 */
	@RequiresPermissions("channel:businessInfo:add")
	@Log(title = "业务员加减分", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SalesmanScore salesmanScore)
	{		
		return toAjax(salesmanScoreService.insertSalesmanScore(salesmanScore));
	}

	/**
	 * 修改业务员加减分
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		SalesmanScore salesmanScore = salesmanScoreService.selectSalesmanScoreById(userId);
		mmap.put("salesmanScore", salesmanScore);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存业务员加减分
	 */
	@RequiresPermissions("channel:businessInfo:edit")
	@Log(title = "业务员加减分", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SalesmanScore salesmanScore)
	{		
		return toAjax(salesmanScoreService.updateSalesmanScore(salesmanScore));
	}
	
	/**
	 * 删除业务员加减分
	 */
	@RequiresPermissions("channel:businessInfo:remove")
	@Log(title = "业务员加减分", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(salesmanScoreService.deleteSalesmanScoreByIds(ids));
	}
	
}
